<template>
  <v-card :title="title" @submit="submit" @reset="reset">
    <v-form
      :form-title="formTitle"
      :form-data="formData"
    />
  </v-card>
</template>

<script>
export default {
  props: {
    type: {
      type: String
    }
  },
  data() {
    return {
      title: '编辑',
      formTitle: [
        {
          en: 'id',
          cn: 'id',
          disabled: true
        },
        {
          en: 'slug',
          cn: '标识'
        },
        {
          en: 'name',
          cn: '名称'
        },
        {
          en: 'created_at',
          cn: '创建时间',
          disabled: true
        },
        {
          en: 'updated_at',
          cn: '更新时间',
          disabled: true
        }
      ],
      formData: {
        id: '123',
        slug: '123',
        name: '123',
        created_at: ['团队日志'],
        updated_at: ['广告主']
      }

    }
  },
  created() {
    // 接收传参
    const data = this.$route.params.data
    console.log(data)
    if (data) {
      localStorage.setItem('details', JSON.stringify(data))
      this.formData = this.$route.params.data
    }
    console.log(typeof localStorage.getItem('details'))
    console.log(localStorage.getItem('details') && JSON.parse(localStorage.getItem('details')) || {})
    this.formData = localStorage.getItem('details') && JSON.parse(localStorage.getItem('details')) || {}

    this.$emit('childTitle', this.$route.meta.title1)
  },
  destroyed() {
    localStorage.removeItem('details')
  },
  methods: {
    // 撤销
    reset() {
      this.formData = localStorage.getItem('details') && JSON.parse(localStorage.getItem('details')) || {}
    },
    submit() {
      const data = this.formData
      this.$post('action/user/savePwd', data)
        .then(res => {
          console.log(res)
        })
    }
  }
}
</script>

<style scoped>

</style>
